
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1
 * @Author : WangRuoyu 
 * @Date : 2023/5/15 10:58
 */

#include "iostream"

using namespace std;

int main() {
    int res = 0;
    int n;
    int last = 0;
    int num = 0;
    while (1) {
        cin >> n;
        if (n == 0) {
            break;
        } else if (n == 1) {
            num++;
            res++;
            last = 1;
        } else {
            num++;
            if (num == 1 || last == 1) {
                last = 2;
            } else {
                last += 2;
            }
            res += last;
        }
    }
    cout << res;
    return 0;
}